#include<stdio.h>

int n;
int arr[100000]={0};

int find(int x,int y)
{
    //找第一个>=target,就是最左边的数
       int left=0;
        int right=n-1;
        while(left<right)
        {
            int mid=left+(right-left)/2;
            if(arr[mid]>=x)  right=mid;
            if(arr[mid]<x)   left=mid+1;
        }
        if(arr[left]<x)  return 0; 
        int releft=left;

    //找最后一个<=target
        left=0;
        right=n-1;
        while(left<right)
        {
           int mid=left+(right-left+1)/2;
           if(arr[mid]>y)   right=mid-1;
           if(arr[mid]<=y)  left=mid;
        }
        if(arr[left]>y)  return 0;
        return left-releft+1;
     
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    int q=0;
    scanf("%d",&q);
    while(q--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        printf("%d\n",find(x,y));
    }
}